<?php
include_once '../library/config.php';
include_once '../library/httprequesthelper.php';
include_once root.'/model/shenghuodingdanlist.php';
include_once root.'/model/shenghuolist.php';
include_once root.'/model/jifenlist.php';

$req=new HttpRequestHelper();
$req->request();

$entity=new ShengHuoDingDanList();
if($entity->select('myid,usejifen,shuliang,shenghuoid,zongjia')->where('id=? and state=9',array($req['out_trade_no']))->get_first_rows())
{
    $myid=$entity['myid'];
    $usejifen=$entity['usejifen'];
    $zongjia=$entity['zongjia'];
    $shenghuoid=$entity['shenghuoid'];

    $entity=new ShengHuoDingDanList();
    $entity->keyvalue('state','0');
    $entity->update()->where('id=? and state=9',array($req['out_trade_no']))->submit();

    if($usejifen)
    {
        JiFenList::jifenuse($myid,-($usejifen),$req['out_trade_no']);
    }else
    {
        JiFenList::jifenuse($myid,ceil($zongjia),$req['out_trade_no']);
    }
    ShengHuoList::kucunhuizong($shenghuoid,$req['out_trade_no']);
}
echo 'success';
